package au.com.mason.propertyTracker.dto;

import java.math.BigDecimal;

public class SearchParameters {
	public static final int PAGE_SIZE = 20;
	
	private Integer suburbId;
	private Integer regionId;
	private BigDecimal priceFrom;
	private BigDecimal priceTo;
	private Integer page;
	private boolean rental;
	private boolean removed;
	private boolean underContract;
	private boolean sold;
	private boolean priceChanged;
	private boolean monitor;
	private boolean showNext;
	private boolean showPrevious;
	private int numberResults;
	
	public Integer getSuburbId() {
		return suburbId;
	}

	public void setSuburbId(Integer suburbId) {
		this.suburbId = suburbId;
	}

	public BigDecimal getPriceFrom() {
		return priceFrom;
	}

	public void setPriceFrom(BigDecimal priceFrom) {
		this.priceFrom = priceFrom;
	}

	public BigDecimal getPriceTo() {
		return priceTo;
	}

	public void setPriceTo(BigDecimal priceTo) {
		this.priceTo = priceTo;
	}	

	public Integer getRegionId() {
		return regionId;
	}

	public void setRegionId(Integer regionId) {
		this.regionId = regionId;
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}	

	public boolean isRental() {
		return rental;
	}

	public void setRental(boolean rental) {
		this.rental = rental;
	}

	public boolean isRemoved() {
		return removed;
	}

	public void setRemoved(boolean removed) {
		this.removed = removed;
	}

	public boolean isUnderContract() {
		return underContract;
	}

	public void setUnderContract(boolean underContract) {
		this.underContract = underContract;
	}

	public boolean isSold() {
		return sold;
	}

	public void setSold(boolean sold) {
		this.sold = sold;
	}

	public boolean isPriceChanged() {
		return priceChanged;
	}

	public void setPriceChanged(boolean priceChanged) {
		this.priceChanged = priceChanged;
	}

	public boolean isMonitor() {
		return monitor;
	}

	public void setMonitor(boolean monitor) {
		this.monitor = monitor;
	}

	public boolean isShowNext() {
		return showNext;
	}

	public void setShowNext(boolean showNext) {
		this.showNext = showNext;
	}

	public boolean isShowPrevious() {
		return showPrevious;
	}

	public void setShowPrevious(boolean showPrevious) {
		this.showPrevious = showPrevious;
	}
	
	public void setNextAndPrevious(int listSize) {
		numberResults = listSize;
		if (listSize > page*PAGE_SIZE) {
			showNext = true;
		}
		else {
			showNext = false;
		}
		if (page > 1) {
			showPrevious = true;
		}
		else {
			showPrevious = false;
		}
	}
	
	public String getPageResults() {
		return getFirstNumber() + " to " + getSecondNumber() + " of " + numberResults;
	}
	
	private int getFirstNumber() {
		return (page - 1)* 20 + 1;
	}
	
	private int getSecondNumber() {
		int result = (page - 1) * 20 + 21;
		if (result > numberResults) {
			result = numberResults;
		}
		
		return result;
	}

}
